package de.sp.games.snake12k;

import java.util.ArrayList;

import de.sp.games.snake12k.boxes.Box;

//TODO Enum Klasse erstellen

public class SUtil {
	
	private SUtil(){};
	
	public static final int UP = 0;
	public static final int LEFT = 1;
	public static final int RIGHT = 2;
	public static final int DOWN = 3;
	
	// Field Size
	public static int fieldSize = 16;
	
	// Timer for move
	public static int moveTime = 12; // x Update-times 12 standard
	private static int timeCounter = 0;
	
	// Played Time
	public static int time = 0;
	public static boolean isPlayedTimerOn = false;
	
	public static boolean gameOver = false;
	public static int snakeLength = 1;
	public static int startSnakeLength = 1;
	public static int snakeDirection = 0;
	public static int picUpGrowValue = 1;
	
	private static int score;
	
	private static boolean reset = false;
	

	public static boolean needHighScoreUpdate = true; // new

	public static boolean isNomralMode()
	{
		if(picUpGrowValue == 1
				&& fieldSize == 16)
		{
			return true;
		} else { return false; }
	}
	
	public static void fieldResetWithNewField() {
		reset = true;
	}
	
	public static boolean isResetWithNewField() {
		boolean resetx = false;
		if(reset) {
			resetx = true;
			reset = false;
		}
		return resetx;
	}
	
	public static final int actualScore() {
		score = snakeLength * 100 - time;
		// No negative scores
		if(score <= 0) {
			score = 0;
		}
		return score;
	}
	
	public static final void addSnakeLength() {
		snakeLength += picUpGrowValue;
	}
	
	public static final boolean isTimeMove() {
		boolean move = false;
		if (timeCounter == moveTime) {
			move = true;
		}
		return move;
	}
	
	public static final void incrementTimeMoveCounter(){
		timeCounter++;
	}
	
	public static final void resetTimeMoveCounter(){
		timeCounter = 0;
	}
	
	public static final int getPlayedTime() {
		return time;
	}
	
	public static final void startPlayedTime() {
		isPlayedTimerOn = true;
	}
	
	public static final void stopPlayedTime() {
		isPlayedTimerOn = false;
	}
	
	public static final void resetPlayedTime() {
		time = 0;
	}
	
	public static final void incrementPlayedTime() {
		if(isPlayedTimerOn) {
			time++;
		}
	}
	
	public static final boolean checkCollision(final int index, ArrayList<Box> boxList) {
		boolean collision = false;
		if(boxList.get(index).isCollision()) {
			collision = true;
		}
		return collision;
	}
	
	public static final int getBoxArrayIndex(final int indexX, final int indexY, ArrayList<Box> boxList) {
		int index = 0;
		for (int i = 0; i < boxList.size(); i++) {
			if (boxList.get(i).getIndexX() == indexX && boxList.get(i).getIndexY() == indexY) {
				index = i;
			}
		}
		return index;
	}
}
